Imports System.Windows.Forms
Imports System.Data.OracleClient

Public Class digSelectCategory

  Public mBlnIsLoaded As Boolean = False
  Private mObjCommand As OracleCommand
  Private mObjDataReader As OracleDataReader
  Private mArrAbbreviationList As New ArrayList

  Public mStrCategory As String = String.Empty
  Public mStrFECategory As String = String.Empty

  Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
    For Each lObjItem As clsDctnryMemberProperties In lstSelectedDctnry.Items
      mStrCategory = mStrCategory & "_" & UCase(lObjItem.mPrpDesc)
      mStrFECategory = mStrFECategory & StrConv(lObjItem.mPrpDesc, VbStrConv.ProperCase)
    Next
    mStrCategory = mStrCategory.Remove(0, 1)

    Me.DialogResult = System.Windows.Forms.DialogResult.OK
    Me.Close()
  End Sub

  Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
    Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.Close()
  End Sub

  Private Sub digSelectCategory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim lStrQuery As String = String.Empty
    Dim lObjClsListBoxProperties As clsDctnryMemberProperties

    mPrRefreshConn()
    If mBlnIsLoaded = False Then
      lStrQuery = "SELECT * FROM TRDX_TECH_DCTNRY T ORDER BY T.TTD_DESC"
      
      mObjCommand = New OracleCommand(lStrQuery, con)
      mObjDataReader = mObjCommand.ExecuteReader

      While mObjDataReader.Read
        lObjClsListBoxProperties = New clsDctnryMemberProperties
        lObjClsListBoxProperties.mPrpDisplayMember = mObjDataReader("TTD_DESC")
        lObjClsListBoxProperties.mPrpValueMember = mObjDataReader("TTD_ABRVTD")
        lObjClsListBoxProperties.mPrpDesc = mObjDataReader("TTD_DESC")
        lObjClsListBoxProperties.mPrpAbrvtd = mObjDataReader("TTD_ABRVTD")
        mArrAbbreviationList.Add(lObjClsListBoxProperties)
      End While

      For lIntCount As Integer = 0 To mArrAbbreviationList.Count - 1
        lstDctnry.Items.Add(mArrAbbreviationList.Item(lIntCount))
      Next

      lstDctnry.DisplayMember = "mPrpDisplayMember"
      lstDctnry.ValueMember = "mPrpValueMember"
      mBlnIsLoaded = True
      lstDctnry.Focus()
   
    End If

    lstSelectedDctnry.Items.Clear()
    lstDctnry.ClearSelected()
    lstSelectedDctnry.ClearSelected()
    mStrCategory = String.Empty
    mStrFECategory = String.Empty
  End Sub

  Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click, lstDctnry.DoubleClick
    If lstDctnry.Items.Count > 0 Then
      lstSelectedDctnry.Items.Add(lstDctnry.SelectedItem)
      lstSelectedDctnry.DisplayMember = "mPrpDisplayMember"
      lstSelectedDctnry.ValueMember = "mPrpValueMember"
    End If
  End Sub

  Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click, lstSelectedDctnry.DoubleClick
    If lstSelectedDctnry.Items.Count > 0 Then
      lstSelectedDctnry.Items.Remove(lstSelectedDctnry.SelectedItem)
    End If
  End Sub

  Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click
    Try
      Dim lIntSelectedIndex As Integer

      If lstSelectedDctnry.SelectedIndex > 0 Then
        lIntSelectedIndex = lstSelectedDctnry.SelectedIndex
        lstSelectedDctnry.Items.Insert(lstSelectedDctnry.SelectedIndex - 1, lstSelectedDctnry.SelectedItem)
        lstSelectedDctnry.Items.RemoveAt(lstSelectedDctnry.SelectedIndex)
        lstSelectedDctnry.Focus()
        lstSelectedDctnry.SetSelected(lIntSelectedIndex - 1, True)
      End If

    Finally
    End Try
  End Sub

  Private Sub cmdDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDown.Click
    Try
      Dim lIntSelectedIndex As Integer

      If lstSelectedDctnry.SelectedIndex >= 0 And lstSelectedDctnry.SelectedIndex <> lstSelectedDctnry.Items.Count - 1 Then
        lIntSelectedIndex = lstSelectedDctnry.SelectedIndex
        lstSelectedDctnry.Items.Insert(lstSelectedDctnry.SelectedIndex + 2, lstSelectedDctnry.SelectedItem)
        lstSelectedDctnry.Items.RemoveAt(lstSelectedDctnry.SelectedIndex)
        If (lIntSelectedIndex + 2) >= lstSelectedDctnry.Items.Count Then
          lIntSelectedIndex = lstSelectedDctnry.Items.Count - 1
        Else
          lIntSelectedIndex = lIntSelectedIndex + 1
        End If

        lstSelectedDctnry.Focus()
        lstSelectedDctnry.SetSelected(lIntSelectedIndex, True)
      End If

    Finally
    End Try
  End Sub
End Class


Public Class clsDctnryMemberProperties
  Private mStrDisplayMember As String
  Private mStrValueMember As String
  Private mStrDesc As String
  Private mStrAbrvtd As String

  Public Property mPrpDisplayMember() As String
    Get
      Return mStrDisplayMember
    End Get
    Set(ByVal value As String)
      mStrDisplayMember = value
    End Set
  End Property

  Public Property mPrpValueMember() As String
    Get
      Return mStrValueMember
    End Get
    Set(ByVal value As String)
      mStrValueMember = value
    End Set
  End Property

  Public Property mPrpDesc() As String
    Get
      Return mStrDesc
    End Get
    Set(ByVal value As String)
      mStrDesc = value
    End Set
  End Property

  Public Property mPrpAbrvtd() As String
    Get
      Return mStrAbrvtd
    End Get
    Set(ByVal value As String)
      mStrAbrvtd = value
    End Set
  End Property

End Class

